<template>
  <div class="cs-page-container">
    <div class="cs-filter-result">
      <el-table
        v-loading="listLoading"
        :data="list"
        :height="'calc(100vh - 300px)'"
        border
        fit
        size="small"
        highlight-current-row
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
      >

        <el-table-column
          align="center"
          label="id"
        >
          <template slot-scope="{ row }">
            {{ row.id }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="页面"
        >
          <template slot-scope="{ row }">
            {{ row.name }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          fixed="right"
        >
          <template slot-scope="{row}">
            <el-button
              type="primary"
              size="mini"
              @click="onView(row)"
            >查看数据</el-button>
            <el-button
              type="primary"
              size="mini"
              @click="onExport(row)"
            >导出</el-button>
           <el-button
              type="primary"
              size="mini"
              @click="onUpdate(row)"
            >编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { viewList,exportData } from '@/api/es'

export default {
  name: 'EsViewList',
  data() {
    return {
      list: [],
      listLoading: true
    }
  },
  created() {
    this.doSearch()
  },
  methods: {
    doSearch() {
      viewList().then((resp) => {
        this.list = resp.data
        this.listLoading = false
      })
    },

    onUpdate(row) {
      this.$router.push('/bx/es-dev?id=' + row.id)
    },

    onView(row) {
      this.$router.push('/bx/es-view-data?id=' + row.id)
    },
    onExport(row) {
        this.exporting = true
        exportData(row.id, {}).then(resp => {
            // this.$router.push(resp.data)
            window.open(resp.data)
            this.exporting = false
        }).finally(()=> {
            this.exporting = false
        })
    }
  }
}
</script>

<style scoped>
</style>
